programming - load a bitmap (bmp) fileWhat links here?
The code can only handle uncompressed format BMP files.

/**************************************************************************
 *  load_bmp                                                              *
 *    Loads a bitmap file into memory.                                    *
 **************************************************************************/


void load_bmp(char *file,BITMAP *b) { FILE *fp; long index; word num_colors; int x;

/* open the file */ if ((fp = fopen(file,"rb")) == NULL) { printf("Error opening file %s.\n",file); exit(1); }

/* check to see if it is a valid bitmap file */ if (fgetc(fp)!='B' || fgetc(fp)!='M') { fclose(fp); printf("%s is not a bitmap file.\n",file); exit(1); }

/* read in the width and height of the image, and the number of colors used; ignore the rest */ fskip(fp,16); fread(&b->width, sizeof(word), 1, fp); fskip(fp,2); fread(&b->height,sizeof(word), 1, fp); fskip(fp,22); fread(&num_colors,sizeof(word), 1, fp); fskip(fp,6);

/* assume we are working with an 8-bit file */ if (num_colors==0) num_colors=256;



/* try to allocate memory */ if ((b->data = (byte *) malloc((word)(b->width*b->height))) == NULL) { fclose(fp); printf("Error allocating memory for file %s.\n",file); exit(1); }

/* Ignore the palette information for now. See palette.c for code to read the palette info. */ fskip(fp,num_colors*4);

/* read the bitmap */ for(index=(b->height-1)*b->width;index>=0;index-=b->width) for(x=0;xwidth;x++) b->data[(word)index+x]=(byte)fgetc(fp);

fclose(fp); }



from here
programming - load a bitmap (bmp) file
filename:programming - load a bitmap (bmp) file
filename:programming%20%2D%20load%20a%20bitmap%20%28bmp%29%20file
last edit:May 01 2010 14:13:32 (5118 days ago)
ct = 1714960518.000000 = May 05 2024 21:55:18
ft = 1272737612.000000 = May 01 2010 14:13:32
dt = 442222906.000000